home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15024 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.airtime.co.uk!usenet
  2. From: wysiwyg@glympton.airtime.co.uk (Adam L Rice)
  3. Newsgroups: comp.object,comp.lang.eiffel,comp.lang.c++,comp.lang.beta,comp.lang.java,comp.lang.sather
  4. Subject: Re: What Should An Exception Handling Do? -- Clarification of rules
  5. Date: 2 Apr 1996 08:11:44 +0100
  6. Organization: The Rice family.
  7. Message-ID: <4jqjvg$d9@glympton.airtime.co.uk>
  8. References: <4irn11$7ln@mimas.brunel.ac.uk> <4j03p4$fbt@hoho.quake.net> <Doq3sv.MzA@research.att.com> <vwjg2ao6hqp.fsf@osfb.aber.ac.uk>
  9. NNTP-Posting-Host: glympton.airtime.co.uk
  10.  
  11. >The exception facility of e.g. C++ is merely a (rather ad-hoc and
  12. >opaque) way of allowing the definition of what are in effect dynamically
  13. >scoped procedure names, forcibly coupled with non-local control
  14. >transfer.
  15.  
  16. So, let me see if I've understood. What you're basically saying is that
  17. instead of doing (in Java):
  18.  
  19. try {
  20.   sock = new Socket("wallawalla.mit.edu", 3456);
  21. } catch (IOException e) {
  22.   ... // handle the exception
  23. }
  24. ... // use the socket
  25.  
  26. we should do something like:
  27.  
  28. if (Socket.ConnectWillWork("wallawalla.mit.edu", 3456) {
  29.   sock = new Socket("wallawalla.mit.edu", 3456);
  30.   ... // use the socket
  31. } else {
  32.   ... // handle the exception
  33. }
  34.  
  35. Hmmmm... that's a lovely code style! I think we can call this techique
  36. 'APIx2', for obvious reasons.
  37.  
  38. But I'm not entirely clear, it might be you were saying we should do:
  39.  
  40. sock = new Socket("wallawalla.mit.edu", 3456, new CantConnectHandler());
  41. if (!CantConnectHandler.ConnectFailed) {
  42.   ... // use the socket
  43. }
  44.  
  45. // some time later
  46. Class CantConnectHandler implements IOExceptionHandler {
  47.   public int ConnectFailed=false;
  48.   public handle(Object context) {
  49.     ... // handle the exception
  50.   }
  51. }
  52.  
  53. Hmmm... that too is delightful! I can't think of a good name for it, so I
  54. think 'VerboseAndSlow' will have to do, though it doesn't capture the true
  55. joy of using this programming style. I can't help but feel that it's a real
  56. pity that the Java developers weren't open-minded enough to provide
  57. alternate APIs for people who wanted to program using these coding styles.
  58.  
  59.  
  60. Well, I say one thing for you computer scientist types, you certainly know
  61. how to make a guy glad of what he's got! I'll never complain about having to
  62. write a try ... catch statement again!
  63.  
  64. Have a nice day!
  65.  
  66. ,==========================================================================.
  67. | \    /\/( |\    /\//'   | Adam L Rice -|- wysiwyg@glympton.airtime.co.uk |
  68. |  \/\/ /  )| \/\/ / \_|  | Resume: http://www.csv.warwick.ac.uk/~mauhb/cv |
  69. `=========================================================================='
  70.